﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for SanPhamBUS
/// </summary>
public class SanPhamBUS
{
	private SanPhamDAO objSanPhamDAO;
    public SanPhamBUS(string strPath)
    {
        objSanPhamDAO = new SanPhamDAO(strPath);
    }
    public DataSet SelectSanPhamByLoaiSP_NSX(int loaisp, int nsx)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.SelectSanPhamByLoaiSP_NSX(loaisp, nsx);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }

    public DataSet SelectSanPhamByLoaiSP_NSX_Paging(int loaisp, int nsx,
        int tranghienthoi, int sosp_moitrang, out int tongsotrang)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.SelectSanPhamByLoaiSP_NSX_Paging(loaisp, nsx, tranghienthoi, sosp_moitrang, out tongsotrang);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }

    public DataSet SelectSanPham(int id)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.SelectSanPham(id);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public DataSet SelectSanPhamByGia(long giasan, long giatran, string loaisp)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.SelectSanPhamByGia(giasan, giatran, loaisp);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public Boolean InsertSanPham(SanPhamDTO spDto)
    {
        try
        {
            return objSanPhamDAO.InsertSanPham(spDto);
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }

    public Boolean DeleteSanPham(int id)
    {
        try
        {
            return objSanPhamDAO.DeleteSanPham(id);
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);
        }
    }

    public Boolean UpdateSanPham(SanPhamDTO spDto, int type)
    {
        try
        {
            return objSanPhamDAO.UpdateSanPham(spDto, type);
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public Boolean UpdateSoLanXem(int id)
    {
        try
        {
            return objSanPhamDAO.UpdateSoLanXem(id);
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public Boolean UpdateDiemSo(int id, int diem)
    {
        try
        {
            return objSanPhamDAO.UpdateDiemSo(id, diem);
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public DataSet TimKiemSanPham(SanPhamCRT sanpham)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.TimKiemSanPham(sanpham);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
    public DataSet TimKiemSanPham_Paging(SanPhamCRT sanpham, int tranghienthoi, int sosp_moitrang)
    {
        DataSet ds;
        try
        {
            ds = objSanPhamDAO.TimKiemSanPham_Paging(sanpham, tranghienthoi, sosp_moitrang);
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
    }
}
